package com.sina.auto.components.AddContentImpl;

import com.sina.auto.components.AddContentInterface.UploadAddContent;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

import static com.sina.auto.components.AddContentImpl.ImageUtil.MergeImage.mergeImage;
import static com.sina.auto.components.AddContentImpl.ImageUtil.imageCut;

public class UploadImageOutput implements UploadAddContent {
    /**
     * 读取一个文件进行操作。
     * @param Content
     * @param file 一个图片文件作为模板处理
     * @return
     * @throws Exception
     */
    public BufferedImage uploadimageoutput(String Content, File file) throws Exception {

        BufferedImage imgs[] = imageCut(file);

        BufferedImage[] images = {imgs[0],AddString.addString(imgs[1],Content) ,imgs[2]};

        return mergeImage(images,2);
    }

    /**
     * 读取一个缓冲图片数组进行操作
     * @param Content 传入的文字
     * @param imgs 一个缓冲图片数组，必须为三个缓冲图片元素。
     * @return
     * @throws Exception
     */
    public BufferedImage uploadimageoutput(String Content, BufferedImage[] imgs) throws Exception {
        if(imgs.length == 3) {

            BufferedImage[] images = {imgs[0],AddString.addString(imgs[1],Content) ,imgs[2]};

            return mergeImage(images, 2);
        }
        else{
            return null;
        }
    }

    /**
     * 读取三张图片文件
     * @param Content
     * @param file1 头部图片
     * @param file2 中部文件
     * @param file3 尾部文件
     * @return
     * @throws Exception
     */
    public BufferedImage uploadimageoutput(String Content, String file1, String file2, String file3) throws Exception {
        BufferedImage[] imgs = {ImageIO.read(new File(file1)),ImageIO.read(new File(file2)),ImageIO.read(new File(file3))};

        BufferedImage[] images = {imgs[0],AddString.addString(imgs[1],Content) ,imgs[2]};

        return mergeImage(images,2);
    }

    /**
     * 额外读取一个字符串author作为作者，作者将写在时间的后面。
     * @param Content
     * @param file
     * @param author
     * @return
     * @throws Exception
     */
    @Override
    public BufferedImage uploadimageoutputonlyauthor(String Content, String author, File file) throws Exception {
        BufferedImage imgs[] = imageCut(file);

        BufferedImage[] images = {imgs[0],AddString.addStringOnlyAuthor(imgs[1],Content,author) ,imgs[2]};

        return mergeImage(images,2);
    }

    @Override
    public BufferedImage uploadimageoutputonlyauthor(String Content, String author, BufferedImage[] imgs) throws Exception {
        if(imgs.length == 3) {

            BufferedImage[] images = {imgs[0],AddString.addStringOnlyAuthor(imgs[1],Content,author) ,imgs[2]};

            return mergeImage(images, 2);
        }
        else{
            return null;
        }
    }

    @Override
    public BufferedImage uploadimageoutputonlyauthor(String Content, String author, String file1, String file2, String file3) throws Exception {
        BufferedImage[] imgs = {ImageIO.read(new File(file1)),ImageIO.read(new File(file2)),ImageIO.read(new File(file3))};

        BufferedImage[] images = {imgs[0],AddString.addStringOnlyAuthor(imgs[1],Content,author) ,imgs[2]};

        return mergeImage(images,2);
    }

    /**
     * 额外读取一个字符串title作为标题，标题将出现在顶部
     * @param Content
     * @param file
     * @param title
     * @return
     * @throws Exception
     */
    @Override
    public BufferedImage uploadimageoutputonlytitle(String Content, String title, File file) throws Exception {
        BufferedImage imgs[] = imageCut(file);

        BufferedImage[] images = {imgs[0],AddString.addStringOnlyTitle(imgs[1],Content,title) ,imgs[2]};

        return mergeImage(images,2);
    }

    @Override
    public BufferedImage uploadimageoutputonlytitle(String Content, String title, BufferedImage[] imgs) throws Exception {
        if(imgs.length == 3) {

            BufferedImage[] images = {imgs[0],AddString.addStringOnlyTitle(imgs[1],Content,title) ,imgs[2]};

            return mergeImage(images, 2);
        }
        else{
            return null;
        }
    }

    @Override
    public BufferedImage uploadimageoutputonlytitle(String Content, String title, String file1, String file2, String file3) throws Exception {
        BufferedImage[] imgs = {ImageIO.read(new File(file1)),ImageIO.read(new File(file2)),ImageIO.read(new File(file3))};

        BufferedImage[] images = {imgs[0],AddString.addStringOnlyTitle(imgs[1],Content,title) ,imgs[2]};

        return mergeImage(images,2);
    }

    /**
     * 同时添加作者与标题
     * @param Content
     * @param file
     * @param author
     * @param title
     * @return
     * @throws Exception
     */
    @Override
    public BufferedImage uploadimageoutput(String Content, String author, String title, File file) throws Exception {
        BufferedImage imgs[] = imageCut(file);

        BufferedImage[] images = {imgs[0],AddString.addString(imgs[1],Content,author,title) ,imgs[2]};

        return mergeImage(images,2);
    }

    @Override
    public BufferedImage uploadimageoutput(String Content, String author, String title, BufferedImage[] imgs) throws Exception {
        if(imgs.length == 3) {

            BufferedImage[] images = {imgs[0],AddString.addString(imgs[1],Content,author,title) ,imgs[2]};

            return mergeImage(images, 2);
        }
        else{
            return null;
        }
    }

    @Override
    public BufferedImage uploadimageoutput(String Content, String author, String title, String file1, String file2, String file3) throws Exception {
        BufferedImage[] imgs = {ImageIO.read(new File(file1)),ImageIO.read(new File(file2)),ImageIO.read(new File(file3))};

        BufferedImage[] images = {imgs[0],AddString.addString(imgs[1],Content,author,title) ,imgs[2]};

        return mergeImage(images,2);
    }
}
